package com.example.android.ui.me.user.reserve;

import static com.example.android.utils.StringUtil.timestamp2time;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.core.util.Pair;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.android.R;
import com.example.android.adapter.AddReleaseAdapter;
import com.example.android.adapter.ReseverItemAdapter;
import com.example.android.bean.AddReleaseInfo;
import com.example.android.bean.BaseModelTable;
import com.example.android.bean.CarOrder;
import com.example.android.bean.CarRelease;
import com.example.android.utils.BaseModel;
import com.example.android.utils.NetUtil;
import com.example.android.utils.api.CarOrderApi;
import com.example.android.utils.api.CarReleaseApi;
import com.google.android.material.datepicker.MaterialDatePicker;
import com.google.android.material.snackbar.Snackbar;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ReseverListFragment extends Fragment {
    private View root;
    private ReseverItemAdapter carReseverAdapter;
    private Integer status;

    public ReseverListFragment(Integer status) {
        this.status = status;
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        root = inflater.inflate(R.layout.fragment_add_release_list, container, false);
        RecyclerView recyclerView = root.findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.addItemDecoration(new DividerItemDecoration(root.getContext(), DividerItemDecoration.VERTICAL));
        carReseverAdapter = new ReseverItemAdapter(null);
        recyclerView.setAdapter(carReseverAdapter);
        //获得数据
        getList();
        return root;
    }

    private void getList() {
        CarOrder carOrder = new CarOrder();
        // 1-等待使用2-正在使用 3已经还车  4 -已经取消
        if (status != 0) {
            carOrder.setStatus(status);
        }
        NetUtil.INSTANCE.get(NetUtil.INSTANCE.getBaseUrlDev()).create(CarOrderApi.class).getMeCarOrderList(carOrder).observe(getViewLifecycleOwner(), new Observer<BaseModelTable<CarOrder>>() {
            @Override
            public void onChanged(BaseModelTable<CarOrder> listBaseModel) {
                Log.i("TAG", "onChanged: " + listBaseModel.toString());
                if (listBaseModel.getRows() != null) {
                    carReseverAdapter.setList(listBaseModel.getRows());
                }
            }
        });
    }


}